package com.module.recall.service;

import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;

import base.util.Page;

import com.module.antiFake.vo.AntiFakeScanHistory;
import com.module.recall.manager.AntiFakeProductCodeManager;
import com.module.recall.manager.AntiFakeProductRecallManager;
import com.module.recall.vo.AntiFakeProductRecall;
import com.module.sys.LoginSession;
import com.webClient.client.SocketClient;
import com.webClient.service.WebClientService;

public class AntiFakeProductRecallService {
	static SocketClient sClient = null;
	static WebClientService ss = null;
	static Logger logger = Logger.getLogger(AntiFakeProductRecallService.class
			.getName());
	private AntiFakeProductRecallManager recallManager = AntiFakeProductRecallManager
			.getInstance();
	private AntiFakeProductCodeManager codeManager = AntiFakeProductCodeManager
			.getInstance();

	/**
	 * 页面查询列表
	 * 
	 * @param obj
	 * @param start
	 * @param limit
	 * @return
	 * @throws Exception
	 */

	public Page list(AntiFakeProductRecall obj, Integer start, Integer limit)
			throws Exception {
		Page page = new Page();
		page.setStart(start);
		page.setLimit(limit);
		obj.setOrgid(LoginSession.getOrgid());
		Page resultPage = recallManager.listProductRecallPage(obj, page);
		return resultPage;
	}

	/**
	 * 通过码查询出商品相关的批次及商品名称
	 * 
	 * @param codeInfo
	 * @return
	 * @throws Exception
	 */

	public AntiFakeScanHistory getProductBatchNo(String codeInfo)
			throws Exception {
		AntiFakeScanHistory antiFakeScanHistory = new AntiFakeScanHistory();
		antiFakeScanHistory.setCodeInfo(codeInfo);
		codeManager.searchCodeInfoBatchNo(antiFakeScanHistory);
		return antiFakeScanHistory;
	}

	/**
	 * 保存召回信息
	 * 
	 * @param recall
	 * @return
	 * @throws Exception
	 */

	public Map save(AntiFakeProductRecall recall) throws Exception {
		recall.setCreaterid(LoginSession.getUserid());
		boolean isTure = recallManager.saveRecall(recall);
		Map<String, Object> statusMap = new HashMap<String, Object>();
		statusMap.put("state", isTure);
		if (isTure == true) {
			statusMap.put("msg", "保存成功！");
		} else {
			statusMap.put("msg", "保存失败！");
		}
		return statusMap;
	}
}
